package com.example.cms.controller;

import com.example.cms.entity.Customer;
import com.example.cms.pojo.Mesagge;
import com.example.cms.pojo.QueryPage;
import com.example.cms.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName CustomerController
 * @Descriptiom TODO
 * @Author Sunbird
 * @Date 2018/12/12 15:02
 * @Version 1.0
 **/
@RestController
public class CustomerController {
    @Autowired
    private CustomerService customerService;

   /**
    * @Author Sunbird
    * @Description 查询客户信息
    * @Date  2018/12/13
    * @Param
    * @return
    **/
    @RequestMapping(value = "/cus" ,method = RequestMethod.POST)
    public Mesagge cus(Integer curr_page,Mesagge mesagge) {
     List<Customer> list=customerService.getByPageCus(curr_page);
     mesagge.setList(list);
     customerService.NumDataNum(mesagge);
     return mesagge;
    }
    /**
     * @Author Sunbird
     * @Description 新增客户信息
     * @Date  2018/12/13
     * @Param
     * @return
     **/
    @RequestMapping(value = "addCustomer" ,method = RequestMethod.POST)//http://localhost:8080/addCustomer?customerName=ss&customerCompany=ss&customerAddre=ss&customerPhone=ss
    public Mesagge addCustomer(Customer customer ,Mesagge mesagge){
       int i= customerService.addCustomer(customer);
       mesagge.setMesCode(i);
        return mesagge;
    }
    /**
     * @Author Sunbird
     * @Description 更新客户信息
     * @Date  2018/12/13
     * @Param
     * @return
     **/
    @RequestMapping(value="updateCustomer" ,method = RequestMethod.POST)//http://localhost:8080/updateCustomer?customerId=1?customerName=ss&customerCompany=ss&customerAddre=ss&customerPhone=ss
    public Integer updateCustomer(Customer customer){
        return customerService.updateCustomer(customer);
    }


    @RequestMapping(value = "deleCustomer",method = RequestMethod.POST)
    public Mesagge deleCustomer(Customer customer,Mesagge mesagge){
       int i= customerService.deletCustomer(customer);
    mesagge.setMesCode(i);
     return mesagge;
    };

    @RequestMapping(value = "likeCustmoer",method = RequestMethod.GET)
    public Mesagge LikeCustmoerName(QueryPage customerName, Mesagge mesagge){
       System.out.println(customerName.getCustomerName());
       mesagge.setList(customerService.LikeName(customerName,mesagge));
       System.out.println(mesagge.getList());
       return mesagge;
    }
    @RequestMapping("customer")
    public Mesagge customerAll(Mesagge mesagge){
       List<Customer> customers= customerService.getAllCus();
       mesagge.setList(customers);
       mesagge.setMesCode(customers.size());
       return mesagge;
    }
}
